pub fn majority_element(nums: Vec<i32>) -> i32 {
    use std::collections::HashMap;

    let len = nums.len();
    
    if len == 1 {
        return nums[0];
    }
    let mut map: HashMap<&i32, i32> = HashMap::new();
    
    for i in 0..len {
        let n = &nums[i];
        match map.get(n) {
            Some(size) => {
                if (size + 1) * 2 >= len as i32 {
                    return *n;
                } else {
                    map.insert(n, size + 1);
                }
            }
            None => {
                map.insert(n, 1);
            }
        }
    }

    return 0;
}
